﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="About.xaml.cs" company="Nokia Developer Wiki">
//   Copyright (c) 2013 Nokia Developer Wiki. All rights reserved.
// </copyright>
// <summary>
//   The about.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace NokiaDev.RadControlsSample
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    using Cimbalino.Phone.Toolkit.Helpers;
    using Cimbalino.Phone.Toolkit.Services;

    /// <summary>
    /// The about.
    /// </summary>
    public partial class About : INotifyPropertyChanged
    {
        /// <summary>
        /// The application manifest
        /// </summary>
        private readonly ApplicationManifest _applicationManifest;

        /// <summary>
        /// Initializes a new instance of the <see cref="About"/> class.
        /// </summary>
        public About()
        {
            InitializeComponent();

            // class that helps to get the application name and version (that is defined in manifest)
            var applicationManifestService = new ApplicationManifestService();
            _applicationManifest = applicationManifestService.GetApplicationManifest();
        }

        /// <summary>
        /// The property changed.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Gets the application name.
        /// </summary>
        public string ApplicationName
        {
            get
            {
                if (_applicationManifest != null)
                {
                    return _applicationManifest.App.Title;
                }

                return "N/D";
            }
        }

        /// <summary>
        /// Gets the version.
        /// </summary>
        public string Version
        {
            get
            {
                if (_applicationManifest != null)
                {
                    return _applicationManifest.App.Version;
                }

                return "N/D";
            }
        }

        /// <summary>
        /// The on property changed.
        /// </summary>
        /// <param name="propertyName">
        /// The property name.
        /// </param>
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
